package com.medical.server.stock.controller;

import java.util.Arrays;
import java.util.Map;

import com.laozj.common.utils.PageUtils;
import com.laozj.common.utils.R;
import com.medical.server.stock.entity.StockEntity;
import com.medical.server.stock.service.StockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author laozj
 * @email laozj@medical.com
 * @date 2024-09-01 15:00:04
 */
@Api(tags = "仓库接口")
@RestController
@RequestMapping("stock/stock")
public class StockController {

    @Autowired
    private StockService stockService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("查询全部仓库信息接口")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = stockService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("根据id查询仓库信息接口")
    @RequestMapping("/info/{stockId}")
    public R info(@PathVariable("stockId") Long stockId) {
        StockEntity stock = stockService.getById(stockId);

        return R.ok().put("stock", stock);
    }

    /**
     * 保存
     */
    @ApiOperation("保存仓库接口")
    @RequestMapping("/save")
    public R save(@RequestBody StockEntity stock) {
        stockService.save(stock);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("编辑仓库接口")
    @RequestMapping("/update")
    public R update(@RequestBody StockEntity stock) {
        stockService.updateById(stock);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除仓库接口")
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] stockIds) {
        stockService.removeByIds(Arrays.asList(stockIds));

        return R.ok();
    }

}
